package com.wzz.first.ptpProducer;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class One {
    public static void main(String[] args) throws JMSException {
        //1创建工厂
        ConnectionFactory factory = new ActiveMQConnectionFactory("admin","admin","tcp://192.168.1.47:61616");

        //2创建连接
        Connection connection = factory.createConnection();

        //3打开连接
        connection.start();

        //4创建session  方法参数一：是否打开事务 方法参数二：消息确认机制
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        //5创建目的地
        Queue queue = session.createQueue("queue01");

        //6创建生产者
        MessageProducer producer = session.createProducer(queue);

        //7创建消息
        TextMessage text = session.createTextMessage("activeMq");

        //8发送
        producer.send(text);

        //9释放资源
        session.close();
        connection.close();
    }
}
